﻿<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
    style="padding: 20px 30px 0 0;">

    <script type='text/html' template>
        <input type='hidden' name='PID' value="{{ d.params.PID || '' }}"/>
    </script>



    <script type='text/html' template>
                <input type='hidden' name='UserID' value='{{ d.params.UserID || '' }}'  placeholder='用户名' autocomplete='off' class='layui-input'>
            </script>


    <script type='text/html' template>
                <input type='hidden' name='Code' value='{{ d.params.Code || '' }}'  placeholder='会员编号' autocomplete='off' class='layui-input'>
            </script>


    <script type='text/html' template>
                <input type='hidden' name='UserName' value='{{ d.params.UserName || '' }}' placeholder='真实姓名' autocomplete='off' class='layui-input'>
            </script>

    <script type='text/html' template lay-done='layui.data.setUpload(d);'>
                <input type='hidden' name='Photo_Upload' id='Photo_Upload' value='{{ d.params.Photo_Upload || '' }}'  placeholder='请上传图片' autocomplete='off' class='layui-input'>
            </script>


    <script type='text/html' template>
                <input type='hidden' name='Mobile' value='{{ d.params.Mobile || '' }}'  placeholder='手机号' autocomplete='off' class='layui-input'>
            </script>

    <script type='text/html' template>
                        <input type='hidden' name='RMK' value='{{ d.params.RMK || '' }}'  placeholder='备注' autocomplete='off' class='layui-input'>
                    </script>
    <script type='text/html' template>
                        <input type='hidden' name='Source' value='{{ d.params.Source || '' }}'  placeholder='来源 (自由注册，店铺扫码注册等)' autocomplete='off' class='layui-input'>
                    </script>



    <div class='layui-form-item'>
        <label class='layui-form-label'>会员等级<label style="color: red">*</label></label>
        <div class='layui-input-block'>
            <div class='layui-input-inline'>
                <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"Level");'>
                    <select name='Level' id='Level'  lay-search lay-verify='required'>
                    </select>
                </script>
            </div>
        </div>
    </div>

    <div class='layui-form-item'>
        <label class='layui-form-label'>会员有效期至<label style="color: red">*</label></label>
        <div class='layui-input-inline'>
            <script type='text/html' template lay-done='layui.data.datedone(d.params);'>
                <input type='text' name='ValiDate' readonly='readonly' lay-verify='required' id='ValiDate' value='{{ d.params.ValiDate || '' }}' lay-verify='datetime' placeholder='yyyy-MM-dd HH:mm:ss' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div>

    <!-- <div class='layui-form-item'>
        <label class='layui-form-label'>所属店铺</label>
        <div class='layui-input-inline'>
            <script type='text/html' template>
                <input type='text' name='StoreID' value='{{ d.params.StoreID || '' }}' lay-verify='required' placeholder='所属店铺' autocomplete='off' class='layui-input'>
            </script>
        </div>
    </div> -->

    <div class="layui-form-item">

        <label class="layui-form-label">所属店铺<label style="color: red">*</label></label>
        <div class="layui-input-block">
            <script type='text/html' template lay-done='layui.data.getSelSource(d.params,"StoreID");'>
                    <select name="StoreID" xm-select="StoreID" xm-select-search="" lay-verify='required' xm-select-radio="" xm-select-skin="default">
                        <option value=""></option>
                    </select>
                    </script>
        </div>

    </div>



    <div class='layui-form-item'>
        <label class='layui-form-label'>账户状态 <label style="color: red">*</label></label>
        <div class='layui-input-block'>
            <script type='text/html' template>
                    <select name='State_Sel' lay-verify='required'>
                      <option value='0' {{ d.params.State_Sel == '0' ? 'selected' : '' }}>启用</option>
                      <option value='1' {{ d.params.State_Sel == '1' ? 'selected' : '' }}>停用</option>
                    </select>
                </script>
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" value="确认" class="layui-btn">
        </div>
    </div>
</div>

<script type="text/javascript">
    layui.use(['form', 'admin', 'upload', 'laydate', 'formSelects'], function () {
        var form = layui.form;//required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证） 自定义值
        var formSelects = layui.formSelects;
    });

    layui.data.getSelSource = function (d, sourceName) {
        layui.use(['admin', 'form', 'formSelects'], function () {
            var $ = layui.$;
            var form = layui.form;
            var admin = layui.admin;
            var formSelects = layui.formSelects;
            var store = d.StoreID;

            if (sourceName == "Level") {
                admin.req({
                    url: layui.setter.APIUrl + '/shop/Goods_memberpriceMgr/getLevels', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res) {
                        //$("#SupplierID_SelSource").append("<option value=''>全部</option>");
                        layui.each(res.Data, function (index, eachdata) {
                            var strIsSel = '';
                            if (eachdata.Level == d.Level)
                                strIsSel = "selected='selected'";
                            $("#Level").append("<option value='" + eachdata.Level + "' " + strIsSel + ">" + eachdata.LevelStr + "</option>");
                        });
                        form.render('select');
                    }
                });
            }

            if (sourceName == 'StoreID') {
                admin.req({
                    url: layui.setter.APIUrl + '/shop/StoreMgr/customerQuery', //实际使用请改成服务端真实接口
                    type: 'post',
                    done: function (res) {
                        formSelects.config('StoreID', {
                            keyName: 'Name',            //自定义返回数据中name的key, 默认 name
                            keyVal: 'PID',            //自定义返回数据中value的key, 默认 value
                        });

                        layui.formSelects.data('StoreID',
                            'local',
                            {
                                arr: res.Data, //要把自己的这个节点去掉
                                linkeage: false,
                                linkageWidth: 140
                            });

                        if (store) {
                            if (store.indexOf(',') == -1) {
                                layui.formSelects.value('StoreID', [store]);
                            } else {
                                layui.formSelects.value('StoreID', res.Data.model.CheckManager.split(','));
                            }
                        }

                    }
                });
            }

        });
    }

    layui.data.setUpload = function (d) {
        layui.use(['upload', 'admin'], function () {
            var $ = layui.$,
                upload = layui.upload,
                admin = layui.admin;
            var formSelects = layui.formSelects;

            //上传头像
            var Photo_UploadSrc = $('#Photo_Upload');
            upload.render({
                url: '/WebAPI/file/uploadImg/'
                , elem: '#Photo_UploadBtn'
                , accept: 'images'
                , method: 'get'
                , multiple: true
                , acceptMime: 'image/*'
                , done: function (res) {
                    if (res.ResultCode == 0) {
                        Photo_UploadSrc.val(res.Data.src);
                        layer.msg('上传成功');
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });

            //查看图片
            admin.events.Photo_UploadImg = function (othis) {
                var src = Photo_UploadSrc.val();
                layer.photos({
                    photos: {
                        "title": "查看头像", //相册标题 
                        "data": [{
                            "src": src //原图地址
                        }]
                    }
                    , shade: 0.01
                    , closeBtn: 1
                    , anim: 5
                });
            };

        });
    }

    layui.data.datedone = function (d) {
        layui.use(['laydate'], function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#ValiDate'
                , type: 'datetime'
                , calendar: true
            });
            laydate.val = d.ValiDate;

        });
    }   
</script>